<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>库存盘点管理</title>
	<meta name="decorator" content="default"/>
		<style type="text/css">
		#searchForm div.ui-input-text {
			padding: 0.4em;
			width:10em;
			display:inline-block;
		}
	</style>
</head>
<body>
	<div class="icon-buttons">
		<input type="button" class="leave-clean-session" data-inline="true" data-icon="back" data-iconpos="notext" value="返回"/>
	</div>
	<form:form id="searchForm" modelAttribute="storeInventoryCheck" action="${ctx}/inventory/storeInventoryCheck/" method="post" class="form-input">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="middleCls">
			<label for="employee">操作人：</label>
			<select id="employee" data-inline="true" data-native-menu="false">
				<c:forEach var="e" items="${fns:getEmployee()}">
					<option value="${e.key}" ${eid == e.key ? 'selected' : '' }>${e.value}</option>
				</c:forEach>
			</select>
			<input type="button" id="startCheck" data-inline="true"  value="开始库存盘点"/>
		</div>
		<div class="middleCls">
			<label>开始：</label>
			<input type="date" id="startDate" data-inline="true" name="startDate" value="${startDate}"/>
			<label>结束：</label>
			<input type="date" id="endDate" data-inline="true" name="endDate" value="${endDate}"/>
			<input data-inline="true"  type="submit" value="查询"/>
		</div>
	</form:form>
	<tags:message content="${message}"/>
	<div class="form-input">
	<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
		<thead><tr><th>盘点时间</th><th>盘点人</th><th>损失金额（元）</th><th></th></tr></thead>
		<tbody>
		<c:if test="${empty  page.list}">
			<tr>
				<td colspan="4">没有检索到数据</td>
			</tr>
		</c:if>
		<c:forEach items="${page.list}" var="storeInventoryCheck">
			<tr id="${storeInventoryCheck.id}">
				<td>
					${fns:formatDate(storeInventoryCheck.checkTime, "yyyy-MM-dd HH:mm:ss")}
				</td>
				<td>${storeInventoryCheck.employee.name}</td>
				<td>${fns:getLostMoney(storeInventoryCheck.id)}</td>
				<td class="operateTD" id="${storeInventoryCheck.id}">
					<input type="button" data-inline="true" data-icon="arrow-d" data-iconpos="notext">
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			$(".operateTD").click(function(){
				operateMenu(this.id);
			});
			$("#contentTable tbody tr").click(function(e){
				if (!this.id) {
					return;
				}
				$("#contentTable tbody tr").removeClass("select_active");
				$(this).addClass("select_active");
				window.location.href = "${ctx}/inventory/storeInventoryCheckDetail/list?sic_id=" + this.id;
			});
			$("body").click(function(e){
				$(".ui-icon-arrow-u").removeClass("ui-icon-arrow-u").addClass("ui-icon-arrow-d");
				$(".opreationTR").removeClass("opreationTR");
				$(".opreation").remove();
			});
			$("#startCheck").click(function(){
				var eid = $("#employee").val();
				if (eid) {
					var url = "${ctx}/inventory/storeInventoryCheck/detailList?eid=" + eid; 
					window.location.href = url;
				} else {
					showTip("请首先选择操作人！");
				}
			});
		 	jQuery("#searchForm").validate({
		 		submitHandler: function(form){
		 			var startValue = $("#startDate").val();
					if (!startValue){
						showTip("开始日期必须填写!");
						return;
					}
					var endValue = $("#endDate").val();
					if (!endValue){
						showTip("结束日期必须填写!");
						return;
					}
					if(startValue && endValue){
						 var start = new Date(startValue.replace(/-/g, "/"));
						 var end = new Date(endValue.replace(/-/g, "/"));
						 if (end < start) {
							showTip("结束日期不能大于开始日期!");
							return;
						}
					 }
					 loading("正在提交，请稍等...");
					 form.submit();
				}
	        });
		});
		var item;
		function operateMenu(id){
			item = $("#opreation-"+ id);
			$(".opreationTR").removeClass("opreationTR");
			$(".ui-icon-arrow-u").removeClass("ui-icon-arrow-u").addClass("ui-icon-arrow-d");
			if(item.length > 0) {
				item.remove();
				this.event.stopPropagation();
				return;
			}
			$("#"+id + " .ui-icon-arrow-d").removeClass("ui-icon-arrow-d").addClass("ui-icon-arrow-u");
			$(".opreation").remove();
			var html= "<tr id='opreation-" + id + "' class='opreation'><td colspan='4'>";
				html += "<a data-role='button' data-inline='true' href='${ctx}/inventory/storeInventoryCheckDetail/list?sic_id=" + id + "'>明细</a>";
				html += "<a class='menu-del' data-role='button' data-inline='true' href='#'>删除</a></td></tr>";
			var del = function(){
				var url = "${ctx}/inventory/storeInventoryCheck/delete?id=" + id;
				bossLoginDeletePopup("确定要删除此盘点信息？", url);
			};
			
			$(".menu-del").die().live('click',del);
			$("#" + id).addClass("opreationTR");
			$("#" + id).after(html);
			$("#contentTable").trigger("create");
			this.event.stopPropagation();
		}
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</body>
</html>
